// cf-gym-100570-a
// 题意：
// 给定n(<=2*10^4)个数的序列ai(1<=ai<=60)，现在有m(<=10^6)个询问，
// 每个询问给定一个x，求min{lcm(ai, ai+1, ..., ai+x-1)} (i=1 to n-x+1)。
// 每个询问模除 10^9+7。
//
// 题解：
// 因为每个ai很小，60 以内的素数大概15个左右，所以以i为左端点的区间lcm
// 的值最多只有几十个。所以我们可以固定左端点，然后二分右端点，然后对于
// 一个区间求lcm只需要对素因子预处理出st表就能对每个素因子O(1)求个最大
// 次幂，然后对于一段最长相等的lcm，我们更新最大长度那个答案，最后在O(n)
// 倒过来更新下ans数组，然后对于每个询问就可以O(1)回答了。
//
// ml:run = time -p $bin < input > output
#include <cstdio>
#include <cmath>
#include <vector>

template <class T>
void scan(T & a)
{
	a = 0;
	bool flag = false;
	char ch = std::getchar();
	if (ch == '-')
		flag = true;
	else if (ch >= '0' && ch <= '9')
		a = ch - '0';

	while ((ch = std::getchar()) >= '0' && ch <= '9')
		a = a * 10 + ch - '0';
	if (flag) a = -a;
}

using ll = long long;
ll const mo = 1000000007;
int const maxp = 60;
int const maxn = 20007;
ll powp[maxp][10];
double const eps = 1e-7;
double logp[maxp * 2];
int log22[maxn];
bool not_prime[maxp * 2];
int st[maxp][maxn][20];
int b[maxp][maxn];
ll a[maxn];
int n, m;

std::vector<int> primes;

template <class T>
T abs(T x) { return x < 0 ? -x : x; }

struct data { ll x; double v; };
bool operator==(data const& a, data const& b) { return abs(a.v - b.v) <= eps; }
bool operator<=(data const& a, data const& b) { return a.v + eps < b.v || a == b; }

data ans[maxn];

int log2(int len)
{
    int tmp = 0;
    for (; (1 << tmp) <= len; tmp++);
    return tmp - 1;
}

void init()
{
    for (int i = 0; i < maxn; i++) log22[i] = log2(i);
    for (int i = 2; i <= maxp; i++) {
        if (not_prime[i]) continue;
        primes.push_back(i);
        logp[i] = log(i);
        for (int j = i * i; j <= maxp; j += i)
            not_prime[j] = true;
    }
    for (int i = 1; i <= maxp; i++) {
        powp[i][0] = 1;
        for (int j = 1; j <= 6; j++)
            powp[i][j] = powp[i][j - 1] * i;
    }
}

bool cmp(int a, int b) { return a > b; }

void sparse_table()
{
    for (size_t pi = 0; pi < primes.size(); pi++) {
        auto p = primes[pi];
        for (int i = 0; i < n; i++) {
            b[pi][i] = 0;
            int tmp = a[i];
            for (; !(tmp % p); tmp /= p) b[pi][i]++;
        }

        int len = log22[n];
        for (int i = 0; i < n; i++) st[pi][i][0] = i;
		for (int l = 1; l <= len; l++)
			for (int i = 0; (i + (1<<l) - 1) < n; i++)
				if (cmp(b[pi][ st[pi][i][l - 1] ], b[pi][ st[pi][i + (1<<(l-1))][l - 1] ]))
					st[pi][i][l] = st[pi][i][l - 1];
				else
					st[pi][i][l] = st[pi][i + (1 << (l-1))][l - 1];
    }
}

int query(int pi, int l, int r)
{
    int k = log22[r - l + 1];
    if (cmp(b[pi][ st[pi][l][k] ], b[pi][ st[pi][r - (1<<k) + 1][k] ]))
        return b[pi][st[pi][l][k]];
    else
        return b[pi][st[pi][r - (1<<k) + 1][k]];
}

ll quick(ll a, ll b)
{
    if (!b) return 1;
    ll ret = quick(a, b / 2);
    ret = (ret * ret) % mo;
    if (b & 1) ret = (ret * a) % mo;
    return ret;
}

data calc(int l, int r)
{
    data ret;
    ret.x = 1;
    ret.v = 0;
    for (size_t i = 0; i < primes.size(); i++) {
        ll p = primes[i];
        auto tmp = query(i, l, r);
        ret.x = (ret.x * powp[p][tmp]) % mo;
        ret.v += tmp * logp[p];
    }
    return ret;
}

int lower_bound(int l, int r, data const& last)
{
    auto tmp = last;
    int tl = r, tr = n - 1;
    while (tl + 1 < tr) {
        int mid = (tl + tr) / 2;
        if (calc(l, mid) <= tmp) tl = mid;
        else tr = mid;
    }
    if (calc(l, tr) == tmp) tl = tr;
    return tl;
}

int main()
{
    /* std::ios_base::sync_with_stdio(false); */
    init();
    /* std::cin >> n >> m; */
    scan(n); scan(m);
    for (int i = 0; i < n; i++) scan(a[i]);
        /* std::cin >> a[i]; */
    sparse_table();

    for (int i = 0; i <= n; i++) ans[i].v = 1e100;

    for (int i = 0; i < n; i++) {
        auto last = calc(i, i);
        for (int r = i; r < n; ) {
            // tr is the biggest pos which lcm(i, tr) == lcm(i, r)
            int tr = lower_bound(i, r, last);
            if (last <= ans[tr - i + 1]) ans[tr - i + 1] = last;
            r = tr + 1;
            if (r < n) last = calc(i, r);
        }
    }

    for (int i = n - 1; i >= 1; i--)
        if (ans[i + 1] <= ans[i]) ans[i] = ans[i + 1];

    for (int i = 0, x; i < m; i++) {
        /* std::cin >> x; */
        scan(x);
        printf("%lld\n", ans[x].x);
        /* std::cout << ans[x].x << "\n"; */
    }
}

